define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {
	$scope.form.type = '1';
	$scope.form.accept="gif,jpeg,jpg,png";
	//课程封面上传
	$("#"+$scope.controllerName+" .file_input").change(function() {
		var docObj = $(this)[0];
		var files = docObj.files;

		var fileName = files[0].name;
		var fileType = fileName.substring(fileName.lastIndexOf(".")+1, fileName.length);

		if($scope.form.accept.indexOf(fileType) == -1) {
			alert("请上传"+$scope.form.accept+"类型的文件。");
			return;
		}

		var formData = new FormData(document.getElementById("uploadForm"));
		formData.append("formData", JSON.stringify($scope.form));

		$.ajax({
			type: "POST",
			enctype:'multipart/form-data',
			url: app.urls.app_upload,
			data: formData,
			cache:false,
			processData:false,
			contentType:false,
			success: function(result) {
				$scope.form.icon = result;
				$scope.$apply();
			},
			error:function(result) {
				alert("上传出错。");
			}
		});
	});
	$scope.saveForm = function(){
		if($scope.formCheck()){
			httpService.post(app.urls.collection_selectIfExit,$scope.form,function(data){
				if("0000" === data.code){
					if(data.data==0){
						httpService.post(app.urls.collection_insert,$scope.form,function(data){
							if("0000" === data.code){
								eventBusService.publish("content.page.reload",data.data);
								eventBusService.publish("modal.page.close",{});
				    		}else{
				    			alert(data.msg);
				    		}
						});
					}else{
						alert("该网址已存在");
					}
	    		}else{
	    			alert(data.msg);
	    		}
			});
		}
	}
}}});